dcmotor30 2.2.0
Loading...
Searching...
No Matches
dcmotor30


DC Motor 30 Click

DC Motor 30 Click demo application is developed using the NECTO Studio, ensuring compatibility with mikroSDK's open-source libraries and tools. Designed for plug-and-play implementation and testing, the demo is fully compatible with all development, starter, and mikromedia boards featuring a mikroBUS™ socket.


Click Library

  • Author : Stefan Filipovic
  • Date : Apr 2025.
  • Type : I2C type

Software Support

Example Description

This example demonstrates the control of a DC motor using the DC Motor 30 Click board. It performs motor driving in different modes (forward, brake, reverse, and coast) and periodically reads the output current and fault status.

Example Libraries

  • MikroSDK.Board
  • MikroSDK.Log
  • Click.DCMotor30

Example Key Functions

  • dcmotor30_cfg_setup This function initializes Click configuration structure to initial values.
    void dcmotor30_cfg_setup(dcmotor30_cfg_t *cfg)
    DC Motor 30 configuration object setup function.
    DC Motor 30 Click configuration object.
    Definition dcmotor30.h:244
  • dcmotor30_init This function initializes all necessary pins and peripherals used for this Click board.
    err_t dcmotor30_init(dcmotor30_t *ctx, dcmotor30_cfg_t *cfg)
    DC Motor 30 initialization function.
    DC Motor 30 Click context object.
    Definition dcmotor30.h:220
  • dcmotor30_default_cfg This function executes a default configuration of DC Motor 30 Click board.
    err_t dcmotor30_default_cfg(dcmotor30_t *ctx)
    DC Motor 30 default configuration function.
  • dcmotor30_drive_motor This function drives the motor in the selected PWM control mode state.
    void dcmotor30_drive_motor ( dcmotor30_t *ctx, uint8_t state );
    void dcmotor30_drive_motor(dcmotor30_t *ctx, uint8_t state)
    DC Motor 30 drive motor function.
  • dcmotor30_get_out_current This function reads the current output measurement in mA.
    err_t dcmotor30_get_out_current ( dcmotor30_t *ctx, float *current );
    err_t dcmotor30_get_out_current(dcmotor30_t *ctx, float *current)
    DC Motor 30 get out current function.

Application Init

Initializes the logger and the Click board driver, then sets the default configuration.

void application_init ( void )
{
log_cfg_t log_cfg;
dcmotor30_cfg_t dcmotor30_cfg;
LOG_MAP_USB_UART( log_cfg );
log_init( &logger, &log_cfg );
log_info( &logger, " Application Init " );
// Click initialization.
dcmotor30_cfg_setup( &dcmotor30_cfg );
DCMOTOR30_MAP_MIKROBUS( dcmotor30_cfg, MIKROBUS_1 );
if ( I2C_MASTER_ERROR == dcmotor30_init( &dcmotor30, &dcmotor30_cfg ) )
{
log_error( &logger, " Communication init." );
for ( ; ; );
}
if ( DCMOTOR30_ERROR == dcmotor30_default_cfg ( &dcmotor30 ) )
{
log_error( &logger, " Default configuration." );
for ( ; ; );
}
log_info( &logger, " Application Task " );
}
@ DCMOTOR30_ERROR
Definition dcmotor30.h:268
#define DCMOTOR30_MAP_MIKROBUS(cfg, mikrobus)
MikroBUS pin mapping.
Definition dcmotor30.h:204
void application_init(void)
Definition main.c:43

Application Task

Drives the motor in different states and monitors the current consumption and possible fault conditions.

void application_task ( void )
{
float current = 0;
log_printf( &logger, " Motor state : FORWARD\r\n" );
Delay_ms ( 1000 );
Delay_ms ( 1000 );
dcmotor30_check_fault ( &dcmotor30 );
if ( DCMOTOR30_OK == dcmotor30_get_out_current ( &dcmotor30, &current ) )
{
log_printf( &logger, " Current : %.3f mA\r\n\n", current );
}
log_printf( &logger, " Motor state : BRAKE\r\n" );
Delay_ms ( 1000 );
Delay_ms ( 1000 );
dcmotor30_check_fault ( &dcmotor30 );
if ( DCMOTOR30_OK == dcmotor30_get_out_current ( &dcmotor30, &current ) )
{
log_printf( &logger, " Current : %.3f mA\r\n\n", current );
}
log_printf( &logger, " Motor state : REVERSE\r\n" );
Delay_ms ( 1000 );
Delay_ms ( 1000 );
dcmotor30_check_fault ( &dcmotor30 );
if ( DCMOTOR30_OK == dcmotor30_get_out_current ( &dcmotor30, &current ) )
{
log_printf( &logger, " Current : %.3f mA\r\n\n", current );
}
log_printf( &logger, " Motor state : COAST\r\n" );
Delay_ms ( 1000 );
Delay_ms ( 1000 );
dcmotor30_check_fault ( &dcmotor30 );
if ( DCMOTOR30_OK == dcmotor30_get_out_current ( &dcmotor30, &current ) )
{
log_printf( &logger, " Current : %.3f mA\r\n\n", current );
}
}
@ DCMOTOR30_OK
Definition dcmotor30.h:267
#define DCMOTOR30_MOTOR_COAST
DC Motor 30 motor PWM control mode setting.
Definition dcmotor30.h:168
#define DCMOTOR30_MOTOR_FORWARD
Definition dcmotor30.h:169
#define DCMOTOR30_MOTOR_BRAKE
Definition dcmotor30.h:171
#define DCMOTOR30_MOTOR_REVERSE
Definition dcmotor30.h:170
void application_task(void)
Definition main.c:79

Application Output

This Click board can be interfaced and monitored in two ways:

  • Application Output - Use the "Application Output" window in Debug mode for real-time data monitoring. Set it up properly by following this tutorial.
  • UART Terminal - Monitor data via the UART Terminal using a USB to UART converter. For detailed instructions, check out this tutorial.

Additional Notes and Information

The complete application code and a ready-to-use project are available through the NECTO Studio Package Manager for direct installation in the NECTO Studio. The application code can also be found on the MIKROE GitHub account.